package com.kevin.springboot.demos.controller;

import com.alibaba.fastjson.JSON;
import com.google.common.base.Strings;
import com.kevin.springboot.demos.consts.RtConsts;
import com.kevin.springboot.demos.domain.OrderInfo;
import com.kevin.springboot.demos.service.OrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.websocket.server.PathParam;
import java.util.List;

/**
 * 订单
 * @author: wangyong
 * @date: 2019/8/17 12:15
 */
//@RestController
@RequestMapping("/order")
@Controller
public class OrderController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(OrderController.class);

	@Resource
	private OrderService orderService;

	/**
	 * 获取订单凭证
	 * @param merchantNo 商户号
	 * @param merchantBatchNo 商户批次号
	 */
	@GetMapping("/getOrderVoucher/{merchantNo}/{merchantBatchNo}/{limit}")
	public String getOrderVoucher(@PathVariable String merchantBatchNo, @PathVariable String merchantNo,
			@PathVariable String limit) {
		logger.info("请求参数-商户号:{}-商户批次号:{},限制条数:{}", merchantNo, merchantBatchNo, limit);
		if (Strings.isNullOrEmpty(merchantNo) || Strings.isNullOrEmpty(merchantBatchNo)) {
			this.setRt(RtConsts.PARAMTER_ERROR);
		}


		try {
			List<OrderInfo> orderList = orderService.getOrderList(limit);


			orderService.getMerchantVoucher(orderList,response.getOutputStream());
		} catch (Exception e) {
			logger.error("发生异常:", e);
		}

		return "";
	}


}
